﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Linq;
using HFBizDBLib;

namespace HFBizSystemLib
{
    public partial class xfGroupD : HFBizFormLib.xfBase
    {
        private DataClassDataContext tdc;

        public xfGroupD()
        {
            tdc = new DataClassDataContext();
            InitializeComponent();
        }

        private void sbOk_Click(object sender, EventArgs e)
        {
            if (textEdit1.EditValue.ToString().Length > 0)
            {
                int c = tdc.GroupInfo.Count(q => q.GName == textEdit2.EditValue.ToString() || q.SId == textEdit1.EditValue.ToString());
                if (c > 0)
                {
                    MessageBox.Show("组名已经存在,请确认!");
                }
                else
                {
                    GroupInfo gi = new GroupInfo
                    {
                        SId = textEdit1.EditValue.ToString(),
                        GName = textEdit2.EditValue.ToString(),
                        GPower = "0"
                    };
                    tdc.GroupInfo.InsertOnSubmit(gi);
                    tdc.SubmitChanges();
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("组名不为空,请确认!");
            }
        }

        private void sbCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}
